package cn.wolfcode.wolf2w.listener;

import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.redis.service.IStrategyRedisService;
import cn.wolfcode.wolf2w.redis.util.RedisKeys;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.List;
//@Component
public class RedisDateInitListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyRedisService strategyRedisService ;

    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

        System.out.println("初始化开始------------------------");
        List<Strategy> list = strategyService.list();
        StrategyStatisVO vo = new StrategyStatisVO();
        //获取所有攻略
        for (Strategy strategy : list) {
            //
           if(strategyRedisService.isStrategyVoExist(strategy.getId())){
                continue;
            }
            BeanUtils.copyProperties(strategy,vo );
            vo.setStrategyId(strategy.getId());
            strategyRedisService.setStrategyStatisVO(vo);
        }
        System.out.println("初始化开始------------------------");
    }
}
